var startTime =  "" ;
var endTime = "";
$(function(){
   /* $(window).resize(function(){
        if($(window).width()<1345)
        {
            $("body").width(1345);
        }
        else
        {
            $("body").width($(window).width());
        }
    });*/
    startTime = Date.parse(new Date());
    $('.radio_1 label').click(function(){
        $('.radio_1 label').removeAttr('class') &&  $(this).toggleClass("checked");
    });
    $('.radio_2 label').click(function(){
        $('.radio_2 label').removeAttr('class') &&  $(this).toggleClass("checked");
    });
    $('.radio_3 label').click(function(){
        $('.radio_3 label').removeAttr('class') &&  $(this).toggleClass("checked");
    });
    $(".checkbox label").click(function(){
        $(this).toggleClass("checked");
    });
    $("#suggest").val("");
});
function commit()
{
    //获取第一个问题的选择,并校验是否为空
    var param_1 = $('input:radio[name="timely"]:checked').val();
    if(param_1==undefined){
        alert("请选择敬请是否及时。");
        return;
    }
    //获取第二个问题的选择,校验为空时提示
    if($('input:checkbox[name="alarm"]:checked').length==0){
        alert("请选择您更关注哪一类警情.");
        return;
    }
    var alarm = document.getElementsByName('alarm');
    var param_2 = new Array($('input:checkbox[name="alarm"]:checked').length);
    var k2 = 0;
    for(var i=0; i<alarm.length; i++){
        if(alarm[i].checked){
            param_2[k2] = alarm[i].value;
            k2 = k2+1;
        }
    }
    //获取第三个问题的选择,校验为空时提示
    if($('input:checkbox[name="monitor"]:checked').length==0){
        alert("请选择希望获取哪类监控资源.");
        return;
    }
    var monitor = document.getElementsByName('monitor');
    var param_3 = new Array($('input:checkbox[name="monitor"]:checked').length);
    var k3 = 0;
    for(var i=0; i<monitor.length; i++){
        if(monitor[i].checked){
            param_3[k3] = monitor[i].value;
            k3 = k3+1;
        }
    }
    //获取第四个问题的选择,校验为空时提示
    var param_4 = $('input:radio[name="delay"]:checked').val();
    if(param_4==undefined){
        alert("请选择是否经常卡顿");
        return;
    }
    //获取第五个问题的选择，校验为空时提示
    if($('input:checkbox[name="apply"]:checked').length==0){
        alert("请选择希望提供哪些录像信息的应用.");
        return;
    }
    var apply = document.getElementsByName('apply');
    var param_5 = new Array($('input:checkbox[name="apply"]:checked').length);
    var k5 = 0;
    for(var i=0; i<apply.length; i++){
        if(apply[i].checked){
            param_5[k5] = apply[i].value;
            k5 = k5+1;
        }
    }
    //获取第六个问题的选择,校验为空时提示
    var param_6 = $('input:radio[name="information"]:checked').val();
    if(param_6==undefined){
        alert("请选择是否希望获得资源相关人员的信息.");
        return;
    }
    //获取最后的输入框的内容，校验为空时提示
    var param_7 = $("#suggest").val();
    if(param_7==""){
        alert("请输入您的建议.");
        return;
    }
    endTime = Date.parse(new Date());
    var json = { "authPojo": {"appid": "", "token": ""},
        "questionnaire":{"userId":"4127211","timely":param_1,"policeClassify":param_2, "monitorClassify":param_3,"videoDelay":param_4,
            "videoInfo":param_5,"resourceInfo":param_6,"suggest":param_7,"startTime":startTime,"endTime":endTime}};
    json = JSON.stringify(json);
    $.ajax({
        type:"POST",
        url:"../../main/submitQuestionnaire.do",
        data:json,
        success:function(data){
            data = jQuery.parseJSON(data);
            if(data.result.code=="200"){
                alert("提交成功！");
            }else{
                alert("提交失败！")
            }
        },
        error:function(){
            alert("提交失败!");
        }
    });
}